﻿using CommonServiceLocator;
using Jn698._45GWTool.ViewModels.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WebFirst.Entities;
using static System.Net.Mime.MediaTypeNames;

namespace Jn698._45GWTool.Controls
{
    /// <summary>
    /// AppControl.xaml 的交互逻辑
    /// </summary>
    public partial class AppControl : UserControl
    {
        //AppControlViewModel viewModel = new AppControlViewModel();
        AppControlViewModel viewModel = ServiceLocator.Current.GetInstance<AppControlViewModel>();
        public AppControl()
        {
            InitializeComponent();
            
            combType.SelectedIndex = 0;
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            var Check = (sender as CheckBox);
            if (int.TryParse(Check.Uid,out int CUID))
            {
                //全选
                if (CUID == -1)
                {
                    foreach (var item in viewModel.ObjectIdList)
                        item.IsSelect = true;
                    Check.Uid = "-2";
                    return;
                }
                //全否选
                if (CUID == -2)
                {
                    foreach (var item in viewModel.ObjectIdList)
                        item.IsSelect = false;
                    Check.Uid = "-1";
                    return;
                }
            }
            else
            {
                int index = (int)viewModel.SelectedObject;
                bool result = (bool)viewModel.ObjectIdList[(int)viewModel.SelectedObject].IsSelect ? false : true;
                viewModel.ObjectIdList[index].IsSelect = result;
            }

            

            /*var IsSelects = from s in viewModel.ObjectIdList
                            where s.IsSelect == true
                            select s;

            if (IsSelects.Count() == 5)
            {
                var Text = String.Empty;
                foreach (var ITEM in IsSelects)
                    Text += ITEM.Id + " \n";

                MessageBox.Show(Text);
            }*/

        }

    }
}
